const mysql = require('mysql2');
const fs = require('fs');
const connection = mysql.createConnection({host: 'localhost',user: 'root',password: '123456',database: 'film'});
connection.connect(err => {console.log('')});

const data = fs.readFileSync('xiaoshuo.json', 'utf8');
newData = JSON.parse(data)
const bookList = newData.result.bookList;
for (let index = 0; index < bookList.length; index++) {
    const element = bookList[index];
    sql = `insert into xiaoshuo (bookName,authorName,updateTime,totalWords) values ('${element.bookName.replace(/'/g, "\\'")}','${element.authorName.replace(/'/g, "\\'")}','${element.updateTime}','${element.totalWords}')`
    connection.query(sql, (err) => {if (err) {return console.error('query error:', err.message);}});
}


// const data = fs.readFileSync('piaofang.json', 'utf8');
// newData = JSON.parse(data)
// for (let index = 0; index < newData.list.length; index++) {
//     const element = newData.list[index];
//     sql = `insert into piaofang (filmname,money,time,count) values ('${element.movieInfo.movieName}','${element.sumBoxDesc}','${element.movieInfo.releaseInfo}','${element.showCount}')`
//     connection.query(sql, (err) => {if (err) {return console.error('query error:', err.message);}});
// }
// 结束连接
connection.end();